home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / bipl.zip / PROCS.ZIP / COMMAIZE.ICN < prev    next >
Text File  |  1992-09-28  |  1KB  |  54 lines

  1. ############################################################################
  2. #
  3. #    File:     commaize.icn
  4. #
  5. #    Subject:  Procedures to add commas to real or integers
  6. #
  7. #    Author:   Ralph Griswold and Richard L. Goerwitz
  8. #
  9. #    Date:     September 28, 1992
  10. #
  11. ###########################################################################
  12. #
  13. #    Version:  1.1
  14. #
  15. ###########################################################################
  16. #  
  17. #  Comma-izes reals or integers (e.g. -1040.39 -> "-1,040.39").
  18. #
  19. ############################################################################
  20. #
  21. #  Links:  none
  22. #
  23. ############################################################################
  24.  
  25.  
  26. procedure commaize(s)
  27.  
  28.     local s2, sign
  29.  
  30.     # Don't bother if s is already comma-ized.
  31.     if type(s) == "string" then find(",", s) & fail
  32.  
  33.     # Take sign.  Save chars after the decimal point (if present).
  34.     if s := abs(0 > s)
  35.     then sign := "-" else sign := ""
  36.     s ? {
  37.     s := tab(find(".")) & ="." &
  38.     not pos(0) & s2 := "." || integer(tab(0))
  39.     }
  40.  
  41.     /s2 := ""
  42.     integer(s) ? {
  43.     tab(0)
  44.     while s2 := "," || move(-3) || s2
  45.     if pos(1)
  46.     then s2 ?:= (move(1), tab(0))
  47.     else s2 := tab(1) || s2
  48.     }
  49.     return sign || s2
  50.  
  51. end
  52.  
  53.  
  54.